<!DOCTYPE html>
<html>
<head>
    <meta charset="UTF-8">
    <title>修改</title>
</head>
<script src="/js/global.js"></script>
<link rel="stylesheet" href="/css/font.css" type="text/css"/>
<link rel="stylesheet" href="/css/layui.css" type="text/css"/>
<link rel="stylesheet" href="/css/xadmin.css" type="text/css"/>
<script type="text/javascript" src="/js/layui.js"></script>
<script type="text/javascript" src="/js/xadmin.js"></script>
<link rel="stylesheet" href="/css/style.css" type="text/css"/>
<script type="text/javascript" src="/js/index.js"></script>
<script type="text/javascript" src="/js/jquery-3.5.1.min.js"></script>
<body>

<div class="layui-form" style="margin-top: 15px;">

    <div class="layui-form-item" style="width: 80%;display: none">
        <label class="layui-form-label">ID</label>
        <div class="layui-input-block">
            <input type="text" name="orderid" id="id" lay-verify="required" placeholder="ID"
                   autocomplete="off" class="layui-input" disabled>
        </div>
    </div>

    <div class="layui-form-item" style="width: 80%;">
        <label class="layui-form-label">物流名称</label>
        <div class="layui-input-block">
            <input type="text" name="logisticsname" id="logisticsname" lay-verify="required" placeholder="物流名称"
                   autocomplete="off" class="layui-input">
        </div>
    </div>

    <div class="layui-form-item" style="width: 80%;">
        <label class="layui-form-label">物流单号</label>
        <div class="layui-input-block">
            <input type="text" name="logisticsnum" id="logisticsnum" placeholder="物流单号可以不填由系统生成"
                   autocomplete="off" class="layui-input">
        </div>
    </div>

    <div class="layui-form-item" style="width: 80%; text-align: center;">
        <button class="layui-btn" lay-submit lay-filter="formDemo">发货</button>
    </div>

</div>
<script type="text/javascript">
    layui.use(['laydate', 'form', 'upload'], function () {
        var laydate = layui.laydate,
            form = layui.form,
            upload = layui.upload,
            $ = layui.jquery;

        form.on('submit(formDemo)', function (data) {
            let logisticsnum = data.field.logisticsnum; // 获取库存
            if (logisticsnum) {
                let regexPattern = /^[1-9]\d*$/; // 正整数的正则表达式
                if (!regexPattern.test(logisticsnum)) { // 判断数字是否符合正则表达式
                    layer.msg("物流单号只能是正整数")
                    return false;
                }
            }
            $.post("../accomplish/add", data.field, function (res) {
                if (res.code === 200) {
                    layer.msg(res.msg, {
                        icon: 1,
                        time: 2000
                    }, function () {
                        var index = parent.layer.getFrameIndex(window
                            .name); //获取当前窗口的name
                        parent.layer.close(index); //关闭窗口
                    });
                } else {
                    layer.msg(res.msg, {
                        icon: 5,
                        time: 2000
                    });
                }
            })
        });
    })
</script>
</body>
</html>
